import requests
from util.useragent import get_headers_init_user_agent
from util.logger import get_logger
logger = get_logger("bilibili番剧.log")


page = 1

try:
    logger.info("程序启动了")
    while True:
        logger.debug(f"开始爬取第{page}页")
        url = f'https://api.bilibili.com/pgc/season/index/result?st=1&order=3&season_version=-1&spoken_language_type=-1&area=-1&is_finish=-1&copyright=-1&season_status=-1&season_month=-1&year=-1&style_id=-1&sort=0&page={page}&season_type=1&pagesize=20&type=1'
        headers = {
            'User-Agent': get_headers_init_user_agent()
        }
        response = requests.get(url, headers=headers)
        for data in response.json()["data"]["list"]:
            print(data)
        if response.json()["data"]["has_next"] == 1:
            logger.debug(f"爬取第{page}页完成")
            page += 1
        else:
            break
except Exception as e:
    logger.error(e)
logger.info("程序结束了")




